Preserve all context keys during serialization#50446
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
|
potiuk
left a comment
There was a problem hiding this comment.
Nice one - however, maybe instead of regexp you should parse the requirement with packaging requirements and take name of distribution from there: https://packaging.pypa.io/en/stable/requirements.html
This has additional advantage of actually parsing the requirements and will fail early in case any of the requirements are not following the specification.
931cc1b to
d974c4b
Compare
|
Hello @potiuk, thank you for the suggestion. I modified the code to use |
d974c4b to
451914c
Compare
451914c to
1794d68
Compare
providers/standard/src/airflow/providers/standard/operators/python.py
Outdated
Show resolved
Hide resolved
potiuk
left a comment
There was a problem hiding this comment.
Nice! One, very small nit. Good points with comment removals.
When instantiating a PythonVirtualenvOperator (or subclass), part of the
context is propagated based on the requirements constructor parameter.
The current implementation only adds the 'pendulum' and 'apache-airflow'
context keys for bare package names.
For instance:
* requirements=["pendulum"] -> works
* requirements=["pendulum<3.0"] -> does not work
This change uses 'packaging.requirements' to ensure all version
specifiers are handled correctly.
1794d68 to
857d2cb
Compare
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
| # invalid version format | ||
| "pendulum==3..0", | ||
| # invalid operator (=< instead of <=) | ||
| "apache-airflow=<2.0", | ||
| # same invalid operator on pendulum | ||
| "pendulum=<3.0", | ||
| # totally malformed | ||
| "invalid requirement", |
There was a problem hiding this comment.
We do not account for the case when more than one are passed.
Follow-up to apache#50446 and apache#50521: - Clean up requirements-flattening logic. - Add tests for requirements passed as multi-line strings.
Follow-up to apache#50446 and apache#50521: - Clean up requirements-flattening logic. - Add tests for requirements passed as multi-line strings.
Follow-up to apache#50446 and apache#50521: - Clean up requirements-flattening logic. - Add tests for requirements passed as multi-line strings.
Follow-up to apache#50446 and apache#50521: - Clean up requirements-flattening logic. - Add tests for requirements passed as multi-line strings.
Follow-up to apache#50446 and apache#50521: - Clean up requirements-flattening logic. - Add tests for requirements passed as multi-line strings.
When instantiating a PythonVirtualenvOperator (or subclass), part of the
context is propagated based on the requirements constructor parameter.
The current implementation only adds the 'pendulum' and 'apache-airflow'
context keys for bare package names.
For instance:
* requirements=["pendulum"] -> works
* requirements=["pendulum<3.0"] -> does not work
This change uses 'packaging.requirements' to ensure all version
specifiers are handled correctly.
Follow-up to apache#50446 and apache#50521: - Clean up requirements-flattening logic. - Add tests for requirements passed as multi-line strings.
When instantiating a PythonVirtualenvOperator, part of the context is propagated based on the requirements constructor parameter. The current logic implementation prevents 'pendulum' or 'apache-airflow' keys to be added to the Airflow context as soon as a version specifier is used.
For instance this requirement list will have the expected behavior:
Whereas this one will cause the
pendulumobjects to be stripped out of the context:This PR aims to fix these limitations.